package com.chw.admin.storage;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chw.utils.CommonFieldsUtil;
import com.chw.utils.UUIDUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class ChwOutstorageService implements IChwOutstorageService {

	@Autowired
	private ChwOutstorageMapper chwOutstorageMapper;

	// 新增
	@Override
	public int addEntity(ChwOutstorage entity) {
		try {
			String id = UUIDUtil.getUUID();
			entity.setOutstorageId(id);
			CommonFieldsUtil.setCreateValueByCy(entity);
			this.chwOutstorageMapper.insert(entity);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1;
	}

	// 修改
	@Override
	public int updateEntity(ChwOutstorage entity) {
		try {
			// entity.setLastUpdatedDate(new Date());
			// entity.setEnabledFlag("Y");
			CommonFieldsUtil.setUpdateValue(entity);
			// this.chwOutstorageMapper.updateByPrimaryKey(entity);
			this.chwOutstorageMapper.updateByPrimaryKeySelective(entity);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1;
	}

	// 逻辑删除头
	@Override
	public int deleteEntity(String id) {
		try {
			this.chwOutstorageMapper.deleteByStorageId(id);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1;
	}

	// 查询 id
	@Override
	public ChwOutstorage getEntityById(String id) {
		return this.chwOutstorageMapper.selectByPrimaryKey(id);
	}

	// 分页查询
	@Override
	public PageInfo<ChwOutstorage> findEntity(ChwOutstorage entity, Integer currentPage, Integer pageSize) {
		PageHelper.startPage(currentPage.intValue(), pageSize.intValue());
		List<ChwOutstorage> list = this.chwOutstorageMapper.findByEntity(entity);
		return new PageInfo(list);
	}
}